package gunfire.cards;

import basemod.abstracts.CustomCard;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.DamageAction;
import com.megacrit.cardcrawl.actions.common.DrawCardAction;
import com.megacrit.cardcrawl.actions.common.GainBlockAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import gunfire.GunfireMod;
import gunfire.characters.Taizi;
import gunfire.relics.SoulOfTaizi;

import static gunfire.GunfireMod.ELEMENT_DAMAGE_CARD;
import static gunfire.GunfireMod.makeCardPath;

public class AngelicAura extends CustomCard {

    public static final String ID = GunfireMod.makeID(AngelicAura.class.getSimpleName());
    private static final CardStrings cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    public static final String NAME = cardStrings.NAME;
    public static final String DESCRIPTION = cardStrings.DESCRIPTION;
    public static final String IMG = makeCardPath("AngelicAura.png");
    private static final CardRarity RARITY = CardRarity.UNCOMMON;
    private static final CardType TYPE = CardType.SKILL;
    private static final CardTarget TARGET = CardTarget.ALL;
    public static final CardColor COLOR = Taizi.Enums.COLOR_GRAY;
    private static final int COST = 0;

    public AngelicAura() {
        super(ID, NAME, IMG, COST, DESCRIPTION, TYPE, COLOR, RARITY, TARGET);
        this.baseBlock = 10;
        this.baseMagicNumber = this.magicNumber = 1;

        //中途生成的临时牌也要加费处理
        if (CardCrawlGame.dungeon != null && AbstractDungeon.currMapNode != null) {
            int cardNum = AbstractDungeon.actionManager.cardsPlayedThisTurn.size();
            this.costForTurn = cardNum / this.magicNumber;
        }
    }

    @Override
    public void upgrade() {
        if (!this.upgraded) {
            this.upgradeName();
            this.upgradeMagicNumber(1);

            //中途升级也要处理费用
            if (CardCrawlGame.dungeon != null && AbstractDungeon.currMapNode != null) {
                int cardNum = AbstractDungeon.actionManager.cardsPlayedThisTurn.size();
                this.costForTurn = cardNum / this.magicNumber;
            }
        }
    }

    @Override
    public void triggerOnCardPlayed(AbstractCard cardPlayed) {
        int cardNum = AbstractDungeon.actionManager.cardsPlayedThisTurn.size();
        this.costForTurn = cardNum / this.magicNumber;
    }

    @Override
    public void atTurnStart() {
        this.costForTurn = this.cost = 0;
        this.applyPowers();
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        this.addToBot(new GainBlockAction(p, p, this.block));
        for(AbstractMonster mo : AbstractDungeon.getCurrRoom().monsters.monsters){
            if(!mo.isDeadOrEscaped()){
                this.addToBot(new GainBlockAction(mo, p, this.block));
                if(p.hasPower("gunfire:GenerosityPower")){
                    this.addToBot(new GainBlockAction(p, p, this.block));
                }
                if(p.hasRelic("gunfire:SoulOfTaizi")){
                    SoulOfTaizi r = (SoulOfTaizi) p.getRelic("gunfire:SoulOfTaizi");
                    r.flash();
                    r.progress3 += this.block;
                    r.judgeEvolve();
                }
            }
        }
    }

    @Override
    public AbstractCard makeCopy() {
        return new AngelicAura();
    }
}
